package com.parkinginfo.manager;


/*
 * Author: Deepika Gohil
 * 
 * This Activity will be used to show the details
 * of the Parking garage.
 */


import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.ToggleButton;

public class ParkingDetailsActivity extends Activity {

	private ImageButton back_button;
	private ImageButton drivingDirectionButton;
	private ImageButton callButton;
	
	private GarageObject parking = null;

	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.parking_detail);
		
		//get the garage from intert
		if(getIntent().getExtras() !=null)
    	{
			int id = getIntent().getExtras().getInt("id");
			parking = (((ParkingManagerApplication)getApplication()).parkingGarages.get(id));
    	}
		
		
		setUpViews();
	}

	private void setUpViews() 
	{
		back_button = (ImageButton) findViewById(R.id.button_back);
		drivingDirectionButton = (ImageButton) findViewById(R.id.button_directions);
		callButton = (ImageButton) findViewById(R.id.button_call);

		back_button.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) 
			{
				finish();
			}
		});
		
		drivingDirectionButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) 
			{
				String slat = ""+ GoogleParkingActivity.lat;
				String slon = "" + GoogleParkingActivity.lon;
				
				String dlat = ""+parking.latti;
				String dlon = ""+parking.longi;
				
				
				Intent navigation = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr=" 
						+ slat + "," + slon 
						+ "&daddr=" + dlat+ "," + dlon)); 
				startActivity(navigation); 
			}
		});

		callButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				try {
					Intent callIntent = new Intent(Intent.ACTION_CALL);
					callIntent.setData(Uri.parse("tel:0"));
					startActivity(callIntent);
				} catch (ActivityNotFoundException activityException) {
					Log.e("dialing-example", "Call failed", activityException);
				}
			}
		});
		
		String notA = "Not Available";
		
		//initialize the details
		TextView add = (TextView)findViewById(R.id.Address);
		String result = "Address: " + parking.Address;
		add.setText(result);
		
		//intersection and description
		TextView interDesc = (TextView)findViewById(R.id.interSecDescription);
		String inter = parking.interSection;
		String desc = parking.desc;
		
		if(inter == null || inter.equals(""))
				inter = notA;
		if(desc == null || desc.equals(""))
				desc = notA;
		
		result = "Intersection: " + inter;
		result += '\n' + "Description: " + desc;
		interDesc.setText(result);
		
		//telephone
		TextView tele = (TextView)findViewById(R.id.telephone);
		String tel = parking.telephone;	
		if(tel == null)
				tel = notA;
		result = "Telephone: " + tel;
		tele.setText("Telephone: not available!");
		
		//type of parking
		TextView type = (TextView)findViewById(R.id.type);
		result = "Type of Parking: " + parking.type;
		type.setText(result);

		
		//availibility
		TextView ava = (TextView)findViewById(R.id.Availability);
		result = "Available spaces: " + parking.available_spaces +
					'\n'+ "Used spaces: " + parking.used_spaces +
					'\n'+ "Capacity: " + parking.total_capacity;

		ava.setText(result);
		
		//rate details
		TextView rate = (TextView)findViewById(R.id.ratesDetails);
		result = parking.ratesDetails;
		rate.setText(result);
		
		//operational hours details
		TextView hours = (TextView)findViewById(R.id.hoursDetails);
		result = parking.hoursDetails;
		hours.setText(result);
	}
}
